package com.neuedu.hcp.controller;


import com.neuedu.hcp.entity.NursingContent;

import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.service.INursingContentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 */

//http://127.0.0.1:8081/content/contentList
@RestController
@RequestMapping("/content")
public class NursingContentController {
    @Autowired
    private INursingContentService iNursingContentService;
    /**
     * 分页展示数据
     * @param currentPage
     * @param size
     * @param nursingContent
     * @return
     */
    @GetMapping("/contentList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             NursingContent nursingContent){
        return iNursingContentService.getcontentListByPage(currentPage,size,nursingContent);
    }

    /**
     * 插入
     * @param nursingContent
     * @return
     */
    @GetMapping("/insert")
    public RespBean insert(NursingContent nursingContent){
        if(iNursingContentService.insert(nursingContent)<=0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }


    @PostMapping("/update")
    public RespBean update(@RequestBody NursingContent nursingContent){
        if(iNursingContentService.updateById(nursingContent)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除
     * @param nursingId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer nursingId){
        if(iNursingContentService.removeById(nursingId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }


}
